package 力扣;

import java.util.Arrays;

/**
 * @author ZhuYi
 * @create 2024/7/23 14:42
 */
public class 买卖股票的最佳时机2_122 {
    public static void main(String[] args) {
        int[] prices = {7, 6, 4, 3, 1};
        System.out.println(maxProfit(prices));
    }

    public static int maxProfit(int[] prices) {
        int sum = 0, max = 0;
        for (int i = 1; i < prices.length; i++) {
            if (prices[i] > prices[i - 1]) {
                max = prices[i] - prices[i - 1];
                sum += max;
            }
        }
        return sum;
    }
}
